package com.huiquan.vocab.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.huiquan.framework.base.EnhancedBaseDao;
import com.huiquan.vocab.domain.VocabElementLabel;
import com.huiquan.vocab.domain.VocabElementLabelResult;
import com.huiquan.vocab.domain.VocabElementLabelResultDto;
import com.huiquan.vocab.domain.VocabElementLabelWord;
import com.ibatis.sqlmap.client.SqlMapClient;

@Repository
public class VocabElementLabelDao extends EnhancedBaseDao<VocabElementLabel> {

	@Resource(name = "sqlMapClient")
	private SqlMapClient sqlMapClient;

	public static final String space = "VOCAB_ELEMENT_LABEL.";

	public VocabElementLabelDao() {
		super(space);
	}

	public void init() {
		this.update(space + "INIT", sqlMapClient);
	}

	public VocabElementLabel retrieveByLabel(String label) {
		return (VocabElementLabel) this.object(space + "RETRIEVE_BY_LABEL", label, sqlMapClient);
	}

	public int retrieveResultSize(Map<String, Object> param) {
		Integer size = (Integer) this.object(space + "RETRIEVE_RESULT_SIZE", param, sqlMapClient);
		return size == null ? 0 : size;
	}

	@SuppressWarnings("unchecked")
	public List<VocabElementLabelResultDto> retrieveResultList(Map<String, Object> param) {
		return (List<VocabElementLabelResultDto>) this.list(space + "RETRIEVE_RESULT_LIST", param, sqlMapClient);
	}

	public VocabElementLabelResult retrieveResultById(long id) {
		return (VocabElementLabelResult) this.object(space + "RETRIEVE_RESULT_BY_ID", id, sqlMapClient);
	}

	public void updateResult(VocabElementLabelResult result) {
		this.update(space + "UPDATE_RESULT", result, sqlMapClient);
	}
	
	public void updateIsDecorateO(String id,String isDecorateO) {
		Map<String, Object> param = new HashMap<String, Object>();
		param .put("id", id);
		param.put("isDecorateO", isDecorateO);
		
		this.update(space + "UPDATE_IS_DECORATE_O", param, sqlMapClient);
	}
	@SuppressWarnings("unchecked")
	public List<String> retrieveLabelByParent(String parent) {
		
		return (List<String>) this.list(space + "RETRIEVE_LABEL_BY_PARENT", parent, sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<VocabElementLabelWord> retrieveWordList() {
		
		return (List<VocabElementLabelWord>) this.list(space + "RETRIEVE_WORD_LIST", sqlMapClient);
	}

	public void deleteAll() {
		VocabElementLabel label = new VocabElementLabel();
		this.delete(label);
	}

	public void deleteAllResult() {
		this.delete(space + "DELETE_ALL_RESULT", sqlMapClient);
	}

	public void batchInsert(List<VocabElementLabel> labelList) {
		this.insert(space + "BATCH_INSERT", labelList, sqlMapClient);
	}

	public void batchInsertResult(List<VocabElementLabelResultDto> resultList) {
		this.insert(space + "BATCH_INSERT_RESULT", resultList, sqlMapClient);
		
	}

	@SuppressWarnings("unchecked")
	public List<String> retrieveDecorateOWord() {

		return (List<String>) this.list(space + "RETRIEVE_DECORATE_O_WORD", sqlMapClient);
	}

}
